<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="shortcut icon" href="../favicon.ico">
  <title>车型信息</title>
  <link rel="stylesheet" href="../plugins/ElementUI/index-2.3.9.css">
  <link href="../css/common.css" rel="stylesheet">
  <!-- import Vue before Element -->
  <script src="../plugins/ElementUI/vue-2.5.16.js" type="text/javascript"></script>
  <!-- import JavaScript -->
  <script src="../plugins/ElementUI/index-2.3.9.js" type="text/javascript"></script>
  <script src="../plugins/ElementUI/vue-resource.min.js"></script>
  <style>
    .el-dialog{width: 80%}
    .el-dialog__body{
        max-height: 70vh;
        overflow-y: scroll
    }
  </style>
</head>
<body>
  <div id="app" v-cloak v-show="appShow"  class="animated fadeInRight">
    <el-form :model="carVehicleForm" label-width="100px" style="width: 850px">
      <el-row>
        <el-col :span="10">
          <el-form-item label="选择日期">
            <el-date-picker
              v-model="carVehicleForm.datePicker"
              type="daterange"
              align="right"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd HH:mm:ss"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              size="small"
              style="width: 100%">
            </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="车辆型号">
            <el-select v-model="carVehicleForm.carModelCode" clearable placeholder="请选择" size="small">
              <el-option label="YAM32" value="YAM32"></el-option>
              <el-option label="YAM46" value="YAM46"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item>
            <el-button size="small" type="primary" size="small" @click="onSubmit" v-show="resourceMap.queryCarModelInfo">&nbsp;&nbsp;查询&nbsp;&nbsp;</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div>
      <el-button type="primary" size="small" icon="el-icon-circle-plus" @click="newAdd" v-show="resourceMap.saveCarModelInfo">新增</el-button>
      <el-button type="primary" size="small" icon="el-icon-delete" @click="onSelectDel" v-show="resourceMap.deleteCarModelInfo">删除选中</el-button>
    </div>
    <br>
    <!-- table -->
    <el-table :data="tableData.list" ref="tableLayout" border size="small" :max-height="windowHeight" style="width: 100%"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column type="index" ></el-table-column>
      <el-table-column prop="platform" label="制造平台" width=""></el-table-column>
      <el-table-column prop="base" label="生产基地"> </el-table-column>
      <el-table-column prop="carModelCode" label="车辆型号"> </el-table-column>
      <el-table-column prop="gmt_modified" sortable label="修改时间" show-overflow-tooltip></el-table-column>
      <el-table-column label="操作" width="120">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index,scope.row)" v-show="resourceMap.updateCarModelInfo">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <br>
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage"
      :page-sizes="[20,50,100,150,200]"
      :page-size="pageSize"
      layout="sizes, prev, pager, next"
      :total="tableData.totalElement">
    </el-pagination>
    <!-- dialog NewAdd -->
    <el-dialog title="车型信息" :visible.sync="dialogNewAdd" :before-close="beforeClose">
      <!-- 车型信息 -->
      <el-tabs v-model="activeName1" type="border-card" class="dialog-shadow">
        <el-tab-pane label="车型信息" name="first">
          <el-form :model="fixedInfo" :rules="rules" ref="ruleForm1">
            <el-row>
              <el-col :span="8">
                <el-form-item label="生产基地" :label-width="formLabelWidth" prop="base">
                  <el-input size="small" v-model="fixedInfo.base"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="车辆型号" :label-width="formLabelWidth" prop="carModelCode">
                  <el-input size="small" v-model="fixedInfo.carModelCode"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="制造平台" :label-width="formLabelWidth" prop="platform">
                  <el-input size="small" v-model="fixedInfo.platform"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-form :model="basicInfo" :rules="rules" ref="ruleForm2">
            <el-row>
              <!-- <el-col :span="8">
                <el-form-item label="VIN" :label-width="formLabelWidth" prop="basicVinCode">
                  <el-input size="small" v-model="basicInfo.basicVinCode"></el-input>
                </el-form-item>
              </el-col> -->
              <el-col :span="8">
                <el-form-item label="最高车速" :label-width="formLabelWidth" prop="basicMaxSpeed">
                  <el-input size="small" v-model="basicInfo.basicMaxSpeed" >
                    <i slot="suffix" class="el-input__icon">km/h</i>
                  </el-input>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="8">
                <el-form-item label="各档位转动比" :label-width="formLabelWidth" prop="basicRotationRatio">
                  <el-input size="small" v-model="basicInfo.basicRotationRatio"></el-input>
                </el-form-item>
              </el-col> -->
              <el-col :span="8">
                <el-form-item label="纯电动续航里程" :label-width="formLabelWidth" prop="basicElectricRange">
                  <el-input size="small" v-model="basicInfo.basicElectricRange" >
                    <i slot="suffix" class="el-input__icon">km</i>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="驱动电机布置型式/位置" label-width="182px" prop="basicDrivePosition">
                  <el-select size="small" v-model="basicInfo.basicDrivePosition" placeholder="请选择" style="width: 100%">
                      <el-option label="轮边电机" value="轮边电机"></el-option>
                      <el-option label="轮毂电机" value="轮毂电机"></el-option>
                      <el-option label="前后双电机" value="前后双电机"></el-option>
                  </el-select>
                </el-form-item>                
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
      </el-tabs>
      <!-- 电池**驱动机 -->
      <el-tabs v-model="activeName2" type="border-card" class="dialog-shadow" @tab-click="TabHandleClick">
        <!-- 电池个数及相关参数 -->
        <el-tab-pane label="电池个数及各个电池相关参数" name="first">
          <el-table :data="batteryInfo" border size="mini" style="width: 100%" max-height="250">
            <el-table-column type="index" width="40"></el-table-column>
            <el-table-column prop="vehicleCode" label="可充电储能系统编码"></el-table-column>
            <el-table-column prop="vehicleType" label="车载充电装置类型"></el-table-column>
            <el-table-column prop="vehicleEnergy" label="车载储能装置类型总能量"></el-table-column>
            <el-table-column prop="vehicleCooling" label="车载储能装置类型冷却方式"></el-table-column>
            <el-table-column  fixed="right" label="操作"  width="100">
              <template slot-scope="scope">
                <el-button  type="text"  size="small" @click="tabEditorClick_battery(scope.$index,scope.row)"> 编辑 </el-button>
                <el-button  type="text"  size="small" @click.native.prevent="tabRemoveClick_battery(scope.$index, batteryInfo)"> 移除 </el-button>
              </template>
            </el-table-column>
          </el-table>
          <br>
          <el-button type="primary" size="small" icon="el-icon-circle-plus" @click="newAdd_battery">新增</el-button>
        </el-tab-pane>
        <!-- 驱动电机个数及相关参数 -->
        <el-tab-pane label="驱动电机个数及各个驱动电机相关参数" name="second">
          <el-table :data="motorInfo" border size="mini" style="width: 100%" max-height="250">
            <el-table-column type="index" width="40"></el-table-column>
            <el-table-column prop="driveType" label="驱动电机冷却方式"></el-table-column>
            <el-table-column prop="driveVoltage" label="额定电压"></el-table-column>
            <el-table-column prop="driveMaxCurrent" label="驱动电机最大工作电流"></el-table-column>
            <el-table-column prop="driveNumber" label="驱动电机序号"></el-table-column>
            <el-table-column prop="driveModel" label="驱动电机型号"></el-table-column>
            <el-table-column prop="drivePower" label="驱动电机峰值功率"></el-table-column>
            <el-table-column prop="driveMaxSpeed" label="驱动电机最高转速"></el-table-column>
            <el-table-column prop="driveMaxTorque" label="驱动电机峰值转距"></el-table-column>
            <el-table-column prop="driveMaxTorqueOut" label="驱动电机最大输出转矩"></el-table-column>
            <el-table-column  fixed="right" label="操作"  width="100">
              <template slot-scope="scope">
                <el-button  type="text"  size="small" @click="tabEditorClick_drive(scope.$index,scope.row)"> 编辑 </el-button>
                <el-button  type="text"  size="small" @click.native.prevent="tabRemoveClick_drive(scope.$index, motorInfo)"> 移除 </el-button>
              </template>
            </el-table-column>
          </el-table>
          <br>
          <el-button type="primary" size="small" icon="el-icon-circle-plus" @click="newAdd_drive">新增</el-button>
        </el-tab-pane> 
      </el-tabs>
      <!-- 燃油信息 -->
      <el-tabs v-model="activeName3" type="border-card" class="dialog-shadow">
        <el-tab-pane label="燃油信息" name="first">
          <el-form :model="fuelInfo" label-width="120px" :rules="rules" ref="ruleForm3">
            <el-row>
              <el-col :span="8">
                <el-form-item label="发动机编号" prop="fuelEngineNo">
                  <el-input size="small" v-model="fuelInfo.fuelEngineNo"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="燃油类型" prop="fuelType">
                  <el-input size="small" v-model="fuelInfo.fuelType"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="燃油编号" prop="fuelNo">
                  <el-input size="small" v-model="fuelInfo.fuelNo"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="最大输出功率" prop="fuelMaxPower">
                  <el-input size="small" v-model="fuelInfo.fuelMaxPower"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="最大输出转距" prop="fuelMaxTorque">
                  <el-input size="small" v-model="fuelInfo.fuelMaxTorque"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button @click="beforeClose" size="small">取 消</el-button>
        <el-button type="primary" @click="newAddSubmit('ruleForm1','ruleForm2','ruleForm3')" size="small">确 定</el-button>
      </div>
    </el-dialog>
    <!-- dialog 电池个数 -->
    <el-dialog title="电池参数编辑" :visible.sync="dialogBattery" :before-close="beforeCloseBattery">
      <el-form :model="batteryInfoObj" :rules="rules" ref="batteries" label-width="200px">
        <el-row> <!-- :md="12" :lg="12" :xl="12" -->
          <el-col :sm="24" :md="12">
            <el-form-item label="可充电储能系统编码" prop="vehicleCode">
              <el-input size="small" v-model="batteryInfoObj.vehicleCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="12">
            <el-form-item label="车载充电装置类型" prop="vehicleType">
              <el-select size="small" v-model="batteryInfoObj.vehicleType" placeholder="请选择" style="width: 100%">
                  <el-option label="磷酸铁锂电池01" value="磷酸铁锂电池01"></el-option>
                  <el-option label="锰酸锂电池02" value="锰酸锂电池02"></el-option>
                  <el-option label="钴酸锂电池03" value="钴酸锂电池03"></el-option>
                  <el-option label="三元材料电池04" value="三元材料电池04"></el-option>
                  <el-option label="聚合物锂离子电池05" value="聚合物锂离子电池05"></el-option>
                  <el-option label="超级电容06" value="超级电容06"></el-option>
                  <el-option label="钛酸锂电池07" value="钛酸锂电池07"></el-option>
                  <el-option label="燃料电池FC" value="燃料电池FC"></el-option>
                  <el-option label="其他储能装置FF" value="其他储能装置FF"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="12">
            <el-form-item label="车载储能装置类型总能量" prop="vehicleEnergy">
              <el-input size="small" v-model="batteryInfoObj.vehicleEnergy"></el-input>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="12">
            <el-form-item label="车载储能装置类型冷却方式" prop="vehicleCooling">
              <el-input size="small" v-model="batteryInfoObj.vehicleCooling"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small"  @click="beforeCloseBattery">取 消</el-button>
        <el-button size="small" type="primary" @click="newAddSubmit_battery('batteries')">确 定</el-button>
      </div>
    </el-dialog>
    <!-- dialog 驱动电机个数 -->
    <el-dialog title="驱动电机编辑" :visible.sync="dialogDrive" :before-close="beforeCloseDrive">
      <el-form :model="motorInfoObj" :rules="rules" ref="motors" label-width="170px">
        <el-row>
          <el-col :sm="24" :md="12" :lg="8">
            <el-form-item label="驱动电机冷却方式" prop="driveType">
              <el-input size="small" v-model="motorInfoObj.driveType"></el-input>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="12" :lg="8">
            <el-form-item label="额定电压" prop="driveVoltage">
              <el-input size="small" v-model="motorInfoObj.driveVoltage"></el-input>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="12" :lg="8">
            <el-form-item label="驱动电机最大工作电流" prop="driveMaxCurrent">
              <el-input size="small" v-model="motorInfoObj.driveMaxCurrent"></el-input>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="12" :lg="8">
            <el-form-item label="驱动电机序号" prop="driveNumber">
              <el-input size="small" v-model="motorInfoObj.driveNumber"></el-input>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="12" :lg="8">
            <el-form-item label="驱动电机型号" prop="driveModel">
              <el-input size="small" v-model="motorInfoObj.driveModel"></el-input>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="12" :lg="8">
            <el-form-item label="驱动电机峰值功率" prop="drivePower">
              <el-input size="small" v-model="motorInfoObj.drivePower"></el-input>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="12" :lg="8">
            <el-form-item label="驱动电机最高转速" prop="driveMaxSpeed">
              <el-input size="small" v-model="motorInfoObj.driveMaxSpeed"></el-input>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="12" :lg="8">
            <el-form-item label="驱动电机峰值转距" prop="driveMaxTorque">
              <el-input size="small" v-model="motorInfoObj.driveMaxTorque"></el-input>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="12" :lg="8">
            <el-form-item label="驱动电机最大输出转矩" prop="driveMaxTorqueOut">
              <el-input size="small" v-model="motorInfoObj.driveMaxTorqueOut"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small"  @click="beforeCloseDrive">取 消</el-button>
        <el-button size="small" type="primary" @click="newAddSubmit_drive('motors')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</body>
  <script src="../plugins/Underscore/underscore-min.js"></script>
  <script src="../js/ApiRequest.js"></script>
  <script>
    var vm = new Vue({
      el: '#app',
      data: function() {
        var checkNumber = function(rule, value, callback) {
          if (!value) {
            return callback(new Error('请输入数字值'));
          }
          setTimeout(function(){
            if (!Number(value)) {
              callback(new Error('请输入数字值'));
            } else {
              callback();
            }
          }, 500);
        };
        return { 
          appShow:false,
          carVehicleForm: {},
          resourceMap:storageLocal.getName('carModel'),
          tableData: [],
          formLabelWidth:'120px',
          windowHeight:(window.innerHeight||(document.documentElement&&document.documentElement.clientHeight)||document.body.clientHeight) - 210,
          dialogNewAdd: false,
          dialogBattery:false,
          dialogDrive:false,
          multipleSelection:[],
          activeName1:'first',
          activeName2: 'first',
          activeName3: 'first',
          currentPage:1,
          pageSize: 50,
          fixedInfo:{},//生产基地,车辆型号,制造平台
          basicInfo:{},//车型信息--其他信息
          batteryInfoObj:{},
          batteryInfo:[],
          motorInfoObj:{},
          motorInfo:[],
          fuelInfo:{},
          rules: {//有效性验证规则
            // 车型信息
            base: [
	            {required: true, message: '请输入生产基地', trigger: 'blur'}
	          ],
            carModelCode: [
	            {required: true, message: '请输入车辆型号', trigger: 'blur'}
	          ],
            platform: [
	            {required: true, message: '请输入制造平台', trigger: 'blur'}
	          ],
            // basicVinCode: [
	          //   {required: true, message: '请输入vin', trigger: 'blur'}
	          // ],
            basicMaxSpeed: [
              {validator: checkNumber, trigger: 'blur' }
	          ],
            // basicRotationRatio: [
	          //   {required: true, message: '请输入各档位转动比', trigger: 'blur'}
	          // ],
            basicElectricRange: [
              {validator: checkNumber, trigger: 'blur' }
	          ],
            basicDrivePosition: [
	            {required: true, message: '请选择驱动电机布置型式/位置', trigger: 'change'}
	          ],
            fuelEngineNo: [
	            {required: true, message: '请输入发动机编号', trigger: 'blur'}
            ],
            // 燃油信息
            fuelType: [
	            {required: true, message: '请输入 燃油类型', trigger: 'blur'}
	          ],
            fuelNo: [
	            {required: true, message: '请输入 燃油编号', trigger: 'blur'}
	          ],
            fuelMaxPower: [
	            {required: true, message: '请输入 最大输出功率', trigger: 'blur'}
	          ],
            fuelMaxTorque: [
	            {required: true, message: '请输入 最大输出转距', trigger: 'blur'}
            ],
            // 电池参数
            vehicleCode:[
	            {required: true, message: '请输入 系统编码', trigger: 'blur'}
            ],
            vehicleType:[
	            {required: true, message: '请选择 充电装置类型', trigger: 'change'}
            ],
            vehicleEnergy:[
	            {required: true, message: '请输入 储能装置类型总能量', trigger: 'blur'}
            ],
            vehicleCooling:[
	            {required: true, message: '请输入 储能装置类型冷却方式', trigger: 'blur'}
            ],
            // 驱动电机
            driveType:[
	            {required: true, message: '请输入 驱动电机冷却方式', trigger: 'blur'}
            ],
            driveVoltage:[
	            {required: true, message: '请输入 额定电压', trigger: 'blur'}
            ],
            driveMaxCurrent:[
	            {required: true, message: '请输入 驱动电机最大工作电流', trigger: 'blur'}
            ],
            driveNumber:[
	            {required: true, message: '请输入 驱动电机序号', trigger: 'blur'}
            ],
            driveModel:[
	            {required: true, message: '请输入 驱动电机型号', trigger: 'blur'}
            ],
            drivePower:[
	            {required: true, message: '请输入 驱动电机峰值功率', trigger: 'blur'}
            ],
            driveMaxSpeed:[
	            {required: true, message: '请输入 驱动电机最高转速', trigger: 'blur'}
            ],
            driveMaxTorque:[
	            {required: true, message: '请输入 驱动电机峰值转距', trigger: 'blur'}
            ],
            driveMaxTorqueOut:[
	            {required: true, message: '请输入 驱动电机最大输出转矩', trigger: 'blur'}
            ]
          },
          flag_mode:1,//车型信息==1-新增 0-编辑
          flag_list:1//电池电机==1-新增 0-编辑
        }
      },
      mounted:function(){
        this.$nextTick(function(){
          this.requestModel()
        })
      },
      updated:function(e){
        this.appShow = true
      },
      methods: {
          onSubmit:function() {//查询
            this.currentPage = 1;
            this.requestModel()
          },
          handleSelectionChange:function(val){//table 多选
            this.multipleSelection = val;
          },
          onSelectDel:function() {//删除选中
            if(this.multipleSelection.length == 0){
              this.$message({
                showClose: true,
                message: '提示，还未选中对象',
                type: 'warning',
                duration:1000
              });
              return
            }
            var arry = _.map(vm.multipleSelection, function(num){ 
              return num.id; 
            });
            this.$alert('此操作将删除选中数据, 是否继续?', '提示', {
              confirmButtonText: '确定',
              showCancelButton:true,
              type: 'warning',
              callback: function(action){
                if (action == "confirm") {
                  var data = {allKeys:arry}
                  resourceRequst("/carModel/deleteCarModelInfo",data,function(res){
                    var table = _.filter(vm.tableData.list, function(item){ 
                      return arry.indexOf(item.id) < 0 
                    });
                    vm.tableData.list = table;
                    vm.$message({ type: 'success', message: "删除成功！" });
                  })
                }
              }
            });
          },
// ************车型 新增-编辑************//
          newAdd:function(){//table -- 新增
            this.flag_mode = 1;
            this.fixedInfo = {};
            this.basicInfo = {};
            this.batteryInfo = [];
            this.motorInfo = [];
            this.fuelInfo = {};
            this.dialogNewAdd = true;
          },
          handleEdit:function(index, row) {//table -- 编辑
            this.flag_mode = 0;
            this.fixedInfo = {
              id:row.id?row.id:'',
              index:index,
              gmt_create:row.gmt_create?row.gmt_create:'',
              base:row.base,
              carModelCode:row.carModelCode,
              platform:row.platform,
            };
            this.basicInfo = JSON.parse(row.basicInfo);
            this.batteryInfo = JSON.parse(row.batteryInfo);
            this.motorInfo = JSON.parse(row.motorInfo);
            this.fuelInfo = JSON.parse(row.fuelInfo);
            this.dialogNewAdd = true;
          },
          beforeClose:function(){
            this.dialogNewAdd = false;
            this.$refs.ruleForm1.resetFields();
            this.$refs.ruleForm2.resetFields();
            this.$refs.ruleForm3.resetFields();
          },
          newAddSubmit:function(formName1,formName2,formName3){ //新增/编辑--车型信息-json提交
            this.$refs[formName1].validate(function(valid){
              if(valid){
                vm.$refs[formName2].validate(function(valid){
                  if(valid){
                    vm.$refs[formName3].validate(function(valid){
                      if (valid) {
                        var motorInfo = JSON.stringify(vm.motorInfo);
                        var batteryInfo = JSON.stringify(vm.batteryInfo);
                        var basicInfo = JSON.stringify(vm.basicInfo);
                        var fuelInfo = JSON.stringify(vm.fuelInfo);
                        if(motorInfo == "[]" || batteryInfo == "[]"){
                          vm.$message({
                            message: '请编辑电池个数和驱动电机个数',
                            type: 'warning'
                          });
                          return
                        }
                        var data = {
                          id:vm.fixedInfo.id?vm.fixedInfo.id:'',
                          gmt_create:vm.fixedInfo.gmt_create?vm.fixedInfo.gmt_create:'',
                          base:vm.fixedInfo.base?vm.fixedInfo.base:'',
                          carModelCode:vm.fixedInfo.carModelCode?vm.fixedInfo.carModelCode:'',
                          platform:vm.fixedInfo.platform?vm.fixedInfo.platform:'',
                          motorInfo:motorInfo,
                          batteryInfo:batteryInfo,
                          basicInfo:basicInfo,
                          fuelInfo:fuelInfo
                        }
                        if(vm.flag_mode){
                          resourceRequst("/carModel/saveCarModelInfo",data,function(res){
                              vm.tableData.list.unshift(res.getResult);
                              vm.$message({ message: '添加成功', type: 'success'});
                          })
                        }else{
                          resourceRequst("/carModel/updateCarModelInfo",data,function(res){
                              vm.$message({ message: '修改成功', type: 'success' });
                              vm.requestModel()
                          })
                        }
                        vm.dialogNewAdd = false;

                      } else {
                        console.log('error submit!!');
                        return false;
                      }
                    })
                  }
                });
              }
            });
          },
// ************电池--驱动************//          
          newAdd_battery:function(){//新增电池信息
            this.flag_list = 1;
            this.batteryInfoObj = {};
            this.dialogBattery = true;
            console.log('新增电池信息')
          },
          newAdd_drive:function(){//新增电机信息
            this.flag_list = 1;
            this.motorInfoObj = {};
            this.dialogDrive = true;
            console.log('新增电机信息')
          },
          tabEditorClick_battery:function(index,row) {//编辑电池信息
            this.flag_list = 0;
            row.index = index;
            cookieUtil.setCookie('active_vehicleBattery',row,1)
            this.batteryInfoObj = row
            this.dialogBattery = true
          },
          tabRemoveClick_battery:function(index, rows) {//移除电池信息
            rows.splice(index, 1);
          },
          tabEditorClick_drive:function(index,row) {//编辑电机信息
            this.flag_list = 0;
            row.index = index;
            cookieUtil.setCookie('active_vehicleDrive',row,1)
            this.motorInfoObj = row;
            this.dialogDrive = true
          },
          tabRemoveClick_drive:function(index, rows) {//移除电机信息
            rows.splice(index, 1);
          },
          beforeCloseBattery:function(){
            var data = cookieUtil.getCookie('active_vehicleBattery')
            if(data){
              vm.batteryInfo.splice(data.index,1,data)
              cookieUtil.removeCookie('active_vehicleBattery')
              this.dialogBattery = false;
            }else{
              this.dialogBattery = false;
            }
            this.$refs.batteries.resetFields();
          },
          beforeCloseDrive:function(){
            var data = cookieUtil.getCookie('active_vehicleDrive')
            if(data){
              vm.motorInfo.splice(data.index,1,data)
              cookieUtil.removeCookie('active_vehicleDrive')
              this.dialogDrive = false;
            }else{
              this.dialogDrive = false;
            }
            this.$refs.motors.resetFields();
          },
          newAddSubmit_battery:function(formName){//电池信息提交
            this.$refs[formName].validate(function(valid) {
              if (valid) {
                var data = vm.batteryInfoObj;
                if(vm.flag_list){
                  vm.batteryInfo = vm.batteryInfo.concat(data)
                  console.log('新增',data)
                }else{
                  console.log('编辑',data)
                  cookieUtil.removeCookie('active_vehicleBattery')
                }
                vm.dialogBattery = false
              } else {
                console.log('error submit!!');
                return false;
              }
            });
          },
          newAddSubmit_drive:function(formName){//电机信息提交
            this.$refs[formName].validate(function(valid){
              if (valid) {
                var data = vm.motorInfoObj;
                if(vm.flag_list){
                  vm.motorInfo = vm.motorInfo.concat(data)
                  console.log('新增',data)
                }else{
                  console.log('编辑',data)
                  cookieUtil.removeCookie('active_vehicleDrive')
                }
                vm.dialogDrive = false
              } else {
                console.log('error submit!!');
                return false;
              }
            });
            
          },
// ************************//
          handleSizeChange:function(val) {
            this.pageSize = val;
            this.requestModel()
          },
          handleCurrentChange:function(val) {
            this.requestModel()
          },
          TabHandleClick:function(tab, event) {//切换 Tab
            console.log(tab.name);
          },
          requestModel:function(){
            var data = {
              "carModelCode":this.carVehicleForm.carModelCode?this.carVehicleForm.carModelCode:'',
              "startTime":this.carVehicleForm.datePicker?this.carVehicleForm.datePicker[0]:'',
              "endTime":this.carVehicleForm.datePicker?this.carVehicleForm.datePicker[1]:'',
              "page":this.currentPage -1 ,
              "pageSize":this.pageSize
            }
            resourceRequst("/carModel/queryCarModelInfo",data,function(res){
                vm.tableData = res.getResult
            })
          },
      }
    })
  </script>
</html>